/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: andres orellana
 * License Type: Evaluation
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class LogDAOImpl implements orm.dao.LogDAO {
	private static final org.apache.log4j.Logger _logger = org.apache.log4j.Logger.getLogger(LogDAOImpl.class);
	public Log loadLogByORMID(int log_id) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return loadLogByORMID(session, log_id);
		}
		catch (Exception e) {
			_logger.error("loadLogByORMID(int log_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log getLogByORMID(int log_id) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return getLogByORMID(session, log_id);
		}
		catch (Exception e) {
			_logger.error("getLogByORMID(int log_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log loadLogByORMID(int log_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return loadLogByORMID(session, log_id, lockMode);
		}
		catch (Exception e) {
			_logger.error("loadLogByORMID(int log_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log getLogByORMID(int log_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return getLogByORMID(session, log_id, lockMode);
		}
		catch (Exception e) {
			_logger.error("getLogByORMID(int log_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log loadLogByORMID(PersistentSession session, int log_id) throws PersistentException {
		try {
			return (Log) session.load(orm.Log.class, new Integer(log_id));
		}
		catch (Exception e) {
			_logger.error("loadLogByORMID(PersistentSession session, int log_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log getLogByORMID(PersistentSession session, int log_id) throws PersistentException {
		try {
			return (Log) session.get(orm.Log.class, new Integer(log_id));
		}
		catch (Exception e) {
			_logger.error("getLogByORMID(PersistentSession session, int log_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log loadLogByORMID(PersistentSession session, int log_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Log) session.load(orm.Log.class, new Integer(log_id), lockMode);
		}
		catch (Exception e) {
			_logger.error("loadLogByORMID(PersistentSession session, int log_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log getLogByORMID(PersistentSession session, int log_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Log) session.get(orm.Log.class, new Integer(log_id), lockMode);
		}
		catch (Exception e) {
			_logger.error("getLogByORMID(PersistentSession session, int log_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log[] listLogByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return listLogByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("listLogByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log[] listLogByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return listLogByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("listLogByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log[] listLogByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Log as Log");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Log[]) list.toArray(new Log[list.size()]);
		}
		catch (Exception e) {
			_logger.error("listLogByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log[] listLogByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Log as Log");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Log[]) list.toArray(new Log[list.size()]);
		}
		catch (Exception e) {
			_logger.error("listLogByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log loadLogByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return loadLogByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("loadLogByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log loadLogByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return loadLogByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("loadLogByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log loadLogByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Log[] logs = listLogByQuery(session, condition, orderBy);
		if (logs != null && logs.length > 0)
			return logs[0];
		else
			return null;
	}
	
	public Log loadLogByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Log[] logs = listLogByQuery(session, condition, orderBy, lockMode);
		if (logs != null && logs.length > 0)
			return logs[0];
		else
			return null;
	}
	
	public static java.util.Iterator<Log> iterateLogByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return iterateLogByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("iterateLogByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator<Log> iterateLogByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PinPassPersistentManager.instance().getSession();
			return iterateLogByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("iterateLogByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator<Log> iterateLogByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Log as Log");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			_logger.error("iterateLogByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator<Log> iterateLogByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Log as Log");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			_logger.error("iterateLogByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log createLog() {
		return new orm.Log();
	}
	
	public boolean save(orm.Log log) throws PersistentException {
		try {
			orm.PinPassPersistentManager.instance().saveObject(log);
			return true;
		}
		catch (Exception e) {
			_logger.error("save(orm.Log log)", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Log log) throws PersistentException {
		try {
			orm.PinPassPersistentManager.instance().deleteObject(log);
			return true;
		}
		catch (Exception e) {
			_logger.error("delete(orm.Log log)", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Log log)throws PersistentException {
		try {
			if(log.getClientecli() != null) {
				log.getClientecli().getLog().remove(log);
			}
			
			return delete(log);
		}
		catch(Exception e) {
			_logger.error("deleteAndDissociate()", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Log log, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(log.getClientecli() != null) {
				log.getClientecli().getLog().remove(log);
			}
			
			try {
				session.delete(log);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			_logger.error("deleteAndDissociate()", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Log log) throws PersistentException {
		try {
			orm.PinPassPersistentManager.instance().getSession().refresh(log);
			return true;
		}
		catch (Exception e) {
			_logger.error("refresh(orm.Log log)", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Log log) throws PersistentException {
		try {
			orm.PinPassPersistentManager.instance().getSession().evict(log);
			return true;
		}
		catch (Exception e) {
			_logger.error("evict(orm.Log log)", e);
			throw new PersistentException(e);
		}
	}
	
	public Log loadLogByCriteria(LogCriteria logCriteria) {
		Log[] logs = listLogByCriteria(logCriteria);
		if(logs == null || logs.length == 0) {
			return null;
		}
		return logs[0];
	}
	
	public Log[] listLogByCriteria(LogCriteria logCriteria) {
		return logCriteria.listLog();
	}
}
